#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
const float PI = 3.14;

class Figure{
public:
    virtual string getName()const = 0;
    virtual double getArea()const = 0;
};

class Rectangle
:public Figure
{
public:
    Rectangle( string name,float length,float width)
    :_name(name)
    ,_length(length)
    ,_width(width) 
    {

    }
    string getName()const override{
        return _name;
    }
    double getArea()const override{
        return _length*_width;
    }

private:
    string _name;
    float _length;
    float _width;

};

class Circle
:public Figure
{
    public:
        Circle(string name,float radius)
        :_name(name)
        ,_radius(radius) 
        {

        }

        string getName()const override{
            return _name;
        }

        double getArea()const override{
            return _radius*_radius*PI;
        }
    private:
        string _name;
        float _radius;
};

class Triangle
:public Figure
{
public:
    Triangle(string name,float base,float hight)
   :_name(name)
   ,_base(base)
   ,_hight(hight) 
    {

    }

    string getName()const override{
        return _name;
    }

    double getArea()const override{
        return _base*_hight/2;
    }

private:
    string _name;
    float _base;
    float _hight;
};

void display (Figure &fig){
    cout<<fig.getName()
        <<"的面积是:"
        <<fig.getArea()<<endl;
}

void test(){
    Rectangle r("正方形",10, 10);
    Circle c("圆",15);
    Triangle t("等腰三角形",4,5);
    display(r);
    display(c);
    display(t);
}

int main()
{
    

    test ();
    return 0;
}

